﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Assets.Script.HelpSystem.Reward.Core
{
    public static class InCaseRewardPool
    {
        static List<RewardInfo> list = new List<RewardInfo>();

        static InCaseRewardPool()
        {
            list.Add(new RewardInfo()
            {
                RewardName = "+1前方射击",
                Describe = "+1向前发送的子弹",
                ICOName = "",
                WeightBase = 1,
                Weight = 1,
                ClassName = "AddForwardAtk",
            });

            list.Add(new RewardInfo()
            {
                RewardName = "+1侧向射击",
                Describe = "+1向左和向右发送的子弹",
                ICOName = "",
                WeightBase = 1,
                Weight = 1,
                ClassName = "AddRLAtk",
            });

            list.Add(new RewardInfo()
            {
                RewardName = "+1后方射击",
                Describe = "+1向后发送的子弹",
                ICOName = "",
                WeightBase = 1,
                Weight = 1,
                ClassName = "AddBackAtk",
            });

            list.Add(new RewardInfo()
            {
                RewardName = "+10%子弹大小",
                Describe = "子弹在原本大小上变大10%",
                ICOName = "",
                WeightBase = 1,
                Weight = 1,
                ClassName = "BullteBig_10",
            });

            list.Add(new RewardInfo()
            {
                RewardName = "+10%移动速度",
                Describe = "在原本的基础上，增加10%的移动速度",
                ICOName = "",
                WeightBase = 1,
                Weight = 1,
                ClassName = "AddSpeed_10p",
            });

            list.Add(new RewardInfo()
            {
                RewardName = "+10%攻击力",
                Describe = "使攻击力提升10%",
                ICOName = "",
                WeightBase = 1,
                Weight = 1,
                ClassName = "AddAtk_10p",
            });

            list.Add(new RewardInfo()
            {
                RewardName = "+10%击退距离",
                Describe = "使敌人退的更远",
                ICOName = "",
                WeightBase = 1,
                Weight = 1,
                ClassName = "AddOffsetD_10p",
            });

            list.Add(new RewardInfo()
            {
                RewardName = "+10%击退时间",
                Describe = "使敌人被击退的世界变得更长",
                ICOName = "",
                WeightBase = 1,
                Weight = 1,
                ClassName = "AddOffsetT_10p",
            });

            list.Add(new RewardInfo()
            {
                RewardName = "+10%无敌时间",
                Describe = "被击退后的无敌时间更长",
                ICOName = "",
                WeightBase = 1,
                Weight = 1,
                ClassName = "AddOffsetT_10p",
            });
        }

        public static List<RewardInfo> GetRandom(int num)
        {
            List<RewardInfo> back = new List<RewardInfo>();
            List<RewardInfo> totalList = new List<RewardInfo>();
            foreach (var item in list)
            {
                totalList.Add(item);
            }

            for (int i = 0; i < num; i++)
            {
                var info = GetRandom(totalList);
                back.Add(info);
                totalList.Remove(info);
            }
            return back;
        }

        static RewardInfo GetRandom(List<RewardInfo> totalList)
        {
            float totalWeigh = 0;
            foreach (var item in totalList)
            {
                totalWeigh += item.Weight;
            }
            var f = Random.Range(0, totalWeigh);

            float nowWeight = 0;
            foreach (var item in totalList)
            {
                nowWeight += item.Weight;
                if (f <= nowWeight)
                {
                    return item;
                }
            }

            return totalList[totalList.Count - 1];
        }
    }
}
